<?php
class DataCalculator implements IDatacalculator {
	

	public function calc($arrays,$days) {
		$calc_arr = array();
		foreach ($days as $day) {
			foreach ($arrays as $ad_network_arr) {
				foreach ($ad_network_arr as $entity) {
					if ($entity["date"] === $day) {
						$impressions = $entity["impressions"];
						$revenue =  $entity["revenue"];
						if (!isset($calc_arr[$day])) {
							$calc_arr[$day] = array("impressions" => 0,
													"revenue" => 0,
													"date" => $day);
						}
						 $calc_arr[$day]["impressions"]+=$impressions;
						 $calc_arr[$day]["revenue"]+=$revenue;
						 if ($calc_arr[$day]["impressions"] > 0)
							 $calc_arr[$day]["ecpm"] = ( $calc_arr[$day]["revenue"]*1000)/ $calc_arr[$day]["impressions"];
					}
				}
			}
		}
		return array_values($calc_arr);
	}
}